package com.dlu.safe_construction.controller;

import com.dlu.safe_construction.common.ApiResult;
import com.dlu.safe_construction.dto.ManagerEditDTO;
import com.dlu.safe_construction.dto.ManagerInfoDTO;
import com.dlu.safe_construction.model.Manager;
import com.dlu.safe_construction.service.ManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by  lijiaxing on 2022/3/30 20:22
 *
 * @author lijiaxing
 */
@CrossOrigin
@RestController
@RequestMapping("/manager")
@Slf4j
public class ManagerController implements BaseController {

    @Resource
    private ManagerService managerService;

    @PostMapping(value = "/login.json", produces = APPLICATION_JSON)
    public ApiResult<String> login(@RequestParam("accountId") String accountId, @RequestParam("password") String password) {
        return managerService.login(accountId, password);
    }

    @GetMapping(value = "/auth.json", produces = APPLICATION_JSON)
    public ApiResult<Void> auth(@RequestParam("AccessToken") String accessToken) {
        return managerService.auth(accessToken);
    }

    @GetMapping(value = "/info.json", produces = APPLICATION_JSON)
    public ApiResult<ManagerInfoDTO> info(@RequestParam("AccessToken") String accessToken, HttpServletRequest request) {
        return managerService.info(accessToken);
    }

    @PostMapping(value = "/edit.json", produces = APPLICATION_JSON)
    public ApiResult<Void> edit(@RequestBody ManagerEditDTO managerEditDTO) {
        return managerService.edit(managerEditDTO);
    }
}
